package top.IT00544.novel.ctrl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.IT00544.novel.dao.NovelDao;
import top.IT00544.novel.entity.JsonMsg;
import top.IT00544.novel.entity.Novel;
import top.IT00544.novel.service.NovelService;

@Controller
@RequestMapping("/novel")
public class NovelCtrl {
//    private static final Log logger = LogFactory.getLog(NovelCtrl.class);
    private final NovelService novelService;

    public NovelCtrl(NovelService novelService) {
        this.novelService = novelService;
    }
    @RequestMapping("/temp1")
    public String sayHello() {
        return "page/temp";
    }
    /**
     * 查询小说某章节内容
     * @param nov url_db_name,id
     * @return
     */
    @RequestMapping("getChapterContent")
    @ResponseBody
    public String getChapterContent(Novel nov){
        JsonMsg jm = novelService.getChapterContent(nov);
        return jm.toJsonString();
    }
    /**
     * 查询小说所有章节
     * @param nov url_db_name
     * @return
     */
    @RequestMapping("getCatalogs")
    @ResponseBody
    public String getCatalogs(Novel nov){
        JsonMsg jm = novelService.getCatalogs(nov);
        return jm.toJsonString();
    }
    /**
     * 查询全部小说信息
     * @return
     */
    @RequestMapping("novelInfo")
    @ResponseBody
    public String novelInfo(){
        JsonMsg jm = novelService.novelInfo();
        return jm.toJsonString();
    }
    /**
     * 小说导入测试
     *   判断对应路径的小说文件可不可以被正常导入
     * @param novel url_local
     */
    @RequestMapping("novelImportTest")
    @ResponseBody
    public String novelImportTest(Novel novel){
        JsonMsg jm = novelService.totalChapterNum(novel,true);
        return jm.toJsonString();
    }
    /**
     * 新增小说
     * <br>1.保存小说信息
     * <br>2.导入小说到数据库
     * @param novel url_local
     */
    @RequestMapping("novelInsert")
    @ResponseBody
    public String novelInsert(Novel novel){
        JsonMsg jm = novelService.novelInsert(novel);
        return jm.toJsonString();
    }
    /**
     * 读取文本文件目录
     * @param novel url_local
     * @return
     */
    @RequestMapping("totalChapterNum")
    @ResponseBody
    public String totalChapterNum(Novel novel){
        JsonMsg jm = novelService.totalChapterNum(novel,true);
        return jm.toJsonString();
    }

    /**
     * 删除小说
     * @param novel id小说ID
     */
    @RequestMapping("novelDelete")
    @ResponseBody
    public String novelDelete(Novel novel){
        JsonMsg jm = novelService.novelDelete(novel);
        return jm.toJsonString();
    }
}
